let db = require("../db/index");

exports.all = (req, res) => {
  //获取clublist表全部数据
  var sql = "select * from clublist_yang";
  db.query(sql, (err, data) => {
    if (err) {
      return res.send("错误：" + err.message);
    }
    res.send(data);
  });
};
exports.get = (req, res) => {
  //通过id查询数据
  var sql = "select * from clublist_yang where id = ?"; //？用于占位
  db.query(sql, [req.query.id], (err, data) => {
    if (err) {
      return res.send("错误：" + err.message);
    }
    res.send(data);
  });
};

exports.del = (req, res) => {
  //通过id删除数据
  var sql = "delete from clublist_yang where id = ?";
  db.query(sql, [req.query.id], (err, data) => {
    if (err) {
      return res.send("错误：" + err.message);
    }
    res.send(data);
  });
};

exports.add = (req, res) => {
  //向clublist表添加数据
  var sql =
    "insert into clublist_yang (id,name,clubname,QQ,content1,content2,content3,date) values (?,?,?,?,?,?,?,?)";
  db.query(
    sql,
    [
      req.query.id,
      req.query.name,
      req.query.clubname,
      req.query.QQ,
      req.query.content1,
      req.query.content2,
      req.query.content3,
      req.query.date,
    ],
    (err, data) => {
      if (err) {
        return res.send("错误：" + err.message);
      }
      res.send(data);
    }
  );
};

exports.update = (req, res) => {
  //通过id更新数据
  var sql =
    "update clublist_yang set name = ?, clubname = ?, QQ = ?, content1 = ?, content2 = ?, content3 = ?, date = ? where id = ?";
  db.query(
    sql,
    [
      req.query.name,
      req.query.clubname,
      req.query.QQ,
      req.query.content1,
      req.query.content2,
      req.query.content3,
      req.query.date,
      req.query.id,
    ],
    (err, data) => {
      if (err) {
        return res.send("错误：" + err.message);
      }
      res.send(data);
    }
  );
};
